package com.mmdccj.yugu.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: MMDCCJ
 * @date: 2023-12-09 03:32
 */
@Mapper
public interface FollowMapper {
    /**
     * 获取关注列表
     *
     * @param userId 用户id
     * @return List<String> 关注人id列表
     */
    @Select("SELECT followed_id FROM follow WHERE follower_id=#{userId}")
    List<String> getAllFollow(String userId);

    // 关注
    @Insert("INSERT INTO follow (follower_id,followed_id) VALUES(#{followerId},#{followedId})")
    int insertFollow(String followerId, String followedId);

    // 检查是否关注
    @Select("SELECT COUNT(*) FROM follow WHERE follower_id=#{followerId} AND followed_id=#{followedId}")
    int checkFollow(String followerId, String followedId);

    // 取关
    @Delete("DELETE FROM follow WHERE follower_id=#{followerId} AND followed_id=#{followedId}")
    int unFollow(String followerId, String followedId);

    /**
     * 获取所有粉丝的userId
     *
     * @param userId 用户id
     * @return List<String> 粉丝id列表
     */
    @Select("SELECT follower_id FROM follow WHERE followed_id=#{userId}")
    List<String> getAllFans(String userId);
}
